<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Converting</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('kvlclib_converting.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Converting </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="kvlclib_hello_kvlclib"></a>
Hello kvlclib</h1>
<p>This example shows a simple conversion from .kme50 to .csv using kvlclib.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="kvlclib_8h.html">kvlclib.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> check(<span class="keyword">const</span> <span class="keywordtype">char</span>* s, <span class="keywordtype">int</span> stat)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="kvlclib_8h.html#a1d75a67f7d616e0bc534ef1d8c321cf8">kvlcOK</a>){</div><div class="line">        printf(<span class="stringliteral">&quot;%s returned %d\n&quot;</span>, s, stat);</div><div class="line">        exit(1);</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line">    <a class="code" href="kvlclib_8h.html#a0b9cf61f2cc7afc5765a9432153e6fa8">KvlcStatus</a> stat;</div><div class="line">    <a class="code" href="kvlclib_8h.html#a7cd7d86b7a164190a08a811db633b38d">KvlcHandle</a> hnd;</div><div class="line"></div><div class="line">    <span class="comment">// Instantiate converter handle and specify output file + format specifier</span></div><div class="line">    stat = <a class="code" href="group__kvlc__converter.html#ga2ae30246197c77907624f2b1457a104f">kvlcCreateConverter</a>(&amp;hnd, <span class="stringliteral">&quot;outputfile.csv&quot;</span>, <a class="code" href="kvlclib_8h.html#a0e1c91022b73f5b33b9a9d30d8959ee4">KVLC_FILE_FORMAT_CSV</a>);</div><div class="line">    check(<span class="stringliteral">&quot;kvlcCreateConverter&quot;</span>, stat);</div><div class="line"></div><div class="line">    <span class="comment">// Set the input file and specify input format</span></div><div class="line">    stat = <a class="code" href="group__kvlc__converter.html#ga35c9e5d685d55d17308e7755dd96c35c">kvlcSetInputFile</a>(hnd, <span class="stringliteral">&quot;inputfile.kme50&quot;</span>, <a class="code" href="kvlclib_8h.html#a6a2c08efd64bfc6d91cb219189d17d5b">KVLC_FILE_FORMAT_KME50</a>);</div><div class="line">    check(<span class="stringliteral">&quot;kvlcSetInputFile&quot;</span>, stat);</div><div class="line"></div><div class="line">    <span class="comment">// Convert file</span></div><div class="line">    <span class="keywordflow">do</span> {</div><div class="line">        stat = <a class="code" href="group__kvlc__converter.html#ga865806d625b0154696bab9c045f04994">kvlcConvertEvent</a>(hnd);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (stat == <a class="code" href="kvlclib_8h.html#a7fcc44cdd872e306f6b6bfc35148cce7">kvlcERR_FILE_EXISTS</a>)</div><div class="line">            printf(<span class="stringliteral">&quot;File already exists!\n&quot;</span>);</div><div class="line"></div><div class="line">    } <span class="keywordflow">while</span> (stat == <a class="code" href="kvlclib_8h.html#a1d75a67f7d616e0bc534ef1d8c321cf8">kvlcOK</a>); <span class="comment">// kvlcEOF when done</span></div><div class="line"></div><div class="line">    <span class="comment">// Check if conversion terminated correctly</span></div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="kvlclib_8h.html#a0f6193050a76943a33eb1948d3b49df6">kvlcEOF</a>){</div><div class="line">        check(<span class="stringliteral">&quot;kvlcConvertEvent&quot;</span>, stat);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// Check if overruns occured</span></div><div class="line">    stat = <a class="code" href="group__kvlc__converter.html#gaddb00d504e65f243b1e28b2a7c7f23d2">kvlcIsOverrunActive</a>(hnd, &amp;overrun);</div><div class="line">    check(<span class="stringliteral">&quot;kvlcIsOverrunActive&quot;</span>, stat);</div><div class="line">    <span class="keywordflow">if</span> (overrun){</div><div class="line">        printf(<span class="stringliteral">&quot;NOTE! The extracted data contained overrun.\n&quot;</span>);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// Check for truncated CAN FD frames (dlc &gt; 8)</span></div><div class="line">    stat = <a class="code" href="group__kvlc__converter.html#gabf8a016a451ad446ec9723fba939c53b">kvlcIsDataTruncated</a>(hnd, &amp;truncated);</div><div class="line">    check(<span class="stringliteral">&quot;kvlcIsDataTruncated&quot;</span>, stat);</div><div class="line">    <span class="keywordflow">if</span> (truncated){</div><div class="line">        printf(<span class="stringliteral">&quot;NOTE! The extracted data was truncated.\n&quot;</span>);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// Destroy the converter</span></div><div class="line">    stat = <a class="code" href="group__kvlc__converter.html#ga5ddcb1c5b06d99a047661ba1a1bcdacc">kvlcDeleteConverter</a>(hnd);</div><div class="line">    check(<span class="stringliteral">&quot;kvlcDeleteConverter&quot;</span>, stat);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><p>As could be seen, kvlclib does not overwrite files by default. We had to check <a class="el" href="group__kvlc__converter.html#ga865806d625b0154696bab9c045f04994">kvlcConvertEvent</a> for <a class="el" href="kvlclib_8h.html#a7fcc44cdd872e306f6b6bfc35148cce7">kvlcERR_FILE_EXISTS</a>. </p><div class="fragment"><div class="line">stat = <a class="code" href="group__kvlc__converter.html#ga865806d625b0154696bab9c045f04994">kvlcConvertEvent</a>(hnd);</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> (stat == <a class="code" href="kvlclib_8h.html#a7fcc44cdd872e306f6b6bfc35148cce7">kvlcERR_FILE_EXISTS</a>)</div><div class="line">    printf(<span class="stringliteral">&quot;File already exists!\n&quot;</span>);</div></div><!-- fragment --><p>If we want to enable automatic overwrites on the converter, we can set the property <a class="el" href="kvlclib_8h.html#a367688bca5aa3d831365e58de09ed47a">KVLC_PROPERTY_OVERWRITE</a>. </p><div class="fragment"><div class="line"><a class="code" href="kvlclib_8h.html#a0b9cf61f2cc7afc5765a9432153e6fa8">KvlcStatus</a> stat;</div><div class="line"><a class="code" href="kvlclib_8h.html#a7cd7d86b7a164190a08a811db633b38d">KvlcHandle</a> hnd;</div><div class="line"><span class="keywordtype">int</span> prop = 1;</div><div class="line">stat = <a class="code" href="group__kvlc__converter.html#ga5c66494a5c025af27b0eace33e02dbf9">kvlcSetProperty</a>(hnd, <a class="code" href="kvlclib_8h.html#a367688bca5aa3d831365e58de09ed47a">KVLC_PROPERTY_OVERWRITE</a>, &amp;prop, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));</div></div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="kvlclib_properties.html">Properties</a> </dd></dl>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_kvlclib.html">Converter API (kvlclib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
